package com.cy.pj.sys.controller;

import com.cy.pj.common.annotation.RequiredLog;
import com.cy.pj.common.vo.JsonResult;
import com.cy.pj.sys.entity.SysMenu;
import com.cy.pj.sys.service.SysMenuService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//@Controller
//@ResponseBody
@Controller //@Controller+@ResponseBody
@RequestMapping("/menu/")
public class SysMenuController {

	@Autowired
	private SysMenuService sysMenuService;
	private String prefix = "sys";

	@RequiresPermissions("sys:menu:view")
	@GetMapping("/menu_list")
	public String menuview()
	{
		return prefix + "/menu_list";
	}


	@GetMapping("/menu_edit")
	@RequiredLog
	public String menuaddupdateview()
	{
		return prefix + "/menu_edit";
	}

	@RequiresPermissions("sys:menu:update")
	@RequestMapping("doUpdateObject")
	@ResponseBody
	public JsonResult doUpdateObject(SysMenu entity) {
		sysMenuService.updateObject(entity);
		return new JsonResult("update ok");
	}

	@RequiresPermissions("sys:menu:add")
	@RequestMapping("doSaveObject")
	@ResponseBody
	@RequiredLog
	public JsonResult doSaveObject(SysMenu entity) {
		sysMenuService.saveObject(entity);
		return new JsonResult("save ok");
	}
	//menu/doFindZtreeMenuNodes

	@RequestMapping("doFindZtreeMenuNodes")
	@ResponseBody
	public JsonResult doFindZtreeMenuNodes() {
		return new JsonResult(sysMenuService.findZTreeMenuNodes());
	}

	@RequiresPermissions("sys:menu:delete")
	@RequestMapping("doDeleteObject")
	@ResponseBody
	@RequiredLog
	public JsonResult doDeleteObject(Integer id) {
		sysMenuService.deleteObject(id);
		return new JsonResult("delete ok");
	}

	@RequiresPermissions("sys:menu:list")
	@RequestMapping("doFindObjects")
	@ResponseBody
	public JsonResult doFindObjects() {
		return new JsonResult(sysMenuService.findObjects());
	}
}


